/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.indicator;

import org.amuthu.DataStore;
import org.amuthu.TalibMgr;

/**
 *
 * @author prabhu
 */
public class SMA extends AbstractIndicator
{
   private final int period;

   /**
    *
    * @param dataStore
    * @param period
    * @param startOffset
    */
   public SMA(DataStore dataStore, IndicatorQuoteType quoteType, int period, int startOffset)
   {
      super(dataStore, startOffset, quoteType);
      this.period = period;
   }

   /**
    *
    * @return
    */
   @Override
   public double calculate()
   {
      int lastIdx = getLastIndex();
      TalibMgr.getTalib().sma(lastIdx, lastIdx, getInputArray(getQuoteType()), period, TalibMgr.getOutBeginIdx(), TalibMgr.getOutNbElement(), getResultArray());
      return getResultValue();
   }

   @Override
   public int getDayDependency()
   {
      return TalibMgr.getTalib().smaLookback(period) + startOffset;
   }

}
